package org.example.controller.userController;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.example.common.Result;
import org.example.entity.ChatMessage;
import org.example.service.ChatMessageService;
import org.example.service.UserProjectService;
import org.example.utils.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@CrossOrigin
@RestController
@RequestMapping("/api")
public class ChatController {

    @Autowired
    private UserProjectService userProjectService;

    @Autowired
    private ChatMessageService chatMessageService;

    @GetMapping("/projects")
    public Result getProjects() {

        List<String> list=userProjectService.selectUserProject2(TokenUtils.getCurrentUser().getName(), "通过");
        return Result.success(list);

    }

    @GetMapping("/history")
    public Result getHistory(
            @RequestParam String projectName,
            @RequestParam(defaultValue = "1") int page1,
            @RequestParam(defaultValue = "20") int size
    ) {
        Page<ChatMessage> page = new Page<>(page1, size);
        return Result.success(chatMessageService.findByProjectNameOrderByDateDesc(projectName));
    }
}